package emailBox

import (
	"github.com/flipped-aurora/gin-vue-admin/server/global"
	"github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
	"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
	"github.com/flipped-aurora/gin-vue-admin/server/model/emailBox"
	emailBoxReq "github.com/flipped-aurora/gin-vue-admin/server/model/emailBox/request"
	"github.com/flipped-aurora/gin-vue-admin/server/service"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
)

type EmailINBOXApi struct {
}

var emailINBOXService = service.ServiceGroupApp.EmailboxServiceGroup.EmailINBOXService

// CreateEmailINBOX 创建EmailINBOX
// @Tags EmailINBOX
// @Summary 创建EmailINBOX
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body emailBox.EmailINBOX true "创建EmailINBOX"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /emailINBOX/createEmailINBOX [post]
func (emailINBOXApi *EmailINBOXApi) CreateEmailINBOX(c *gin.Context) {
	var emailINBOX emailBox.EmailINBOX
	_ = c.ShouldBindJSON(&emailINBOX)
	if err := emailINBOXService.CreateEmailINBOX(emailINBOX); err != nil {
		global.GVA_LOG.Error("创建失败!", zap.Error(err))
		response.FailWithMessage("创建失败", c)
	} else {
		response.OkWithMessage("创建成功", c)
	}
}

// DeleteEmailINBOX 删除EmailINBOX
// @Tags EmailINBOX
// @Summary 删除EmailINBOX
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body emailBox.EmailINBOX true "删除EmailINBOX"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /emailINBOX/deleteEmailINBOX [delete]
func (emailINBOXApi *EmailINBOXApi) DeleteEmailINBOX(c *gin.Context) {
	var emailINBOX emailBox.EmailINBOX
	_ = c.ShouldBindJSON(&emailINBOX)
	if err := emailINBOXService.DeleteEmailINBOX(emailINBOX); err != nil {
		global.GVA_LOG.Error("删除失败!", zap.Error(err))
		response.FailWithMessage("删除失败", c)
	} else {
		response.OkWithMessage("删除成功", c)
	}
}

// DeleteEmailINBOXByIds 批量删除EmailINBOX
// @Tags EmailINBOX
// @Summary 批量删除EmailINBOX
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.IdsReq true "批量删除EmailINBOX"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"批量删除成功"}"
// @Router /emailINBOX/deleteEmailINBOXByIds [delete]
func (emailINBOXApi *EmailINBOXApi) DeleteEmailINBOXByIds(c *gin.Context) {
	var IDS request.IdsReq
	_ = c.ShouldBindJSON(&IDS)
	if err := emailINBOXService.DeleteEmailINBOXByIds(IDS); err != nil {
		global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
		response.FailWithMessage("批量删除失败", c)
	} else {
		response.OkWithMessage("批量删除成功", c)
	}
}

// UpdateEmailINBOX 更新EmailINBOX
// @Tags EmailINBOX
// @Summary 更新EmailINBOX
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body emailBox.EmailINBOX true "更新EmailINBOX"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /emailINBOX/updateEmailINBOX [put]
func (emailINBOXApi *EmailINBOXApi) UpdateEmailINBOX(c *gin.Context) {
	var emailINBOX emailBox.EmailINBOX
	_ = c.ShouldBindJSON(&emailINBOX)
	if err := emailINBOXService.UpdateEmailINBOX(emailINBOX); err != nil {
		global.GVA_LOG.Error("更新失败!", zap.Error(err))
		response.FailWithMessage("更新失败", c)
	} else {
		response.OkWithMessage("更新成功", c)
	}
}

// FindEmailINBOX 用id查询EmailINBOX
// @Tags EmailINBOX
// @Summary 用id查询EmailINBOX
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query emailBox.EmailINBOX true "用id查询EmailINBOX"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /emailINBOX/findEmailINBOX [get]
func (emailINBOXApi *EmailINBOXApi) FindEmailINBOX(c *gin.Context) {
	var emailINBOX emailBox.EmailINBOX
	_ = c.ShouldBindQuery(&emailINBOX)
	if reemailINBOX, err := emailINBOXService.GetEmailINBOX(emailINBOX.ID); err != nil {
		global.GVA_LOG.Error("查询失败!", zap.Error(err))
		response.FailWithMessage("查询失败", c)
	} else {
		response.OkWithData(gin.H{"reemailINBOX": reemailINBOX}, c)
	}
}

// GetEmailINBOXList 分页获取EmailINBOX列表
// @Tags EmailINBOX
// @Summary 分页获取EmailINBOX列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query emailBoxReq.EmailINBOXSearch true "分页获取EmailINBOX列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /emailINBOX/getEmailINBOXList [get]
func (emailINBOXApi *EmailINBOXApi) GetEmailINBOXList(c *gin.Context) {
	var pageInfo emailBoxReq.EmailINBOXSearch
	_ = c.ShouldBindQuery(&pageInfo)
	if list, total, err := emailINBOXService.GetEmailINBOXInfoList(pageInfo); err != nil {
		global.GVA_LOG.Error("获取失败!", zap.Error(err))
		response.FailWithMessage("获取失败", c)
	} else {
		response.OkWithDetailed(response.PageResult{
			List:     list,
			Total:    total,
			Page:     pageInfo.Page,
			PageSize: pageInfo.PageSize,
		}, "获取成功", c)
	}
}
